package com.china08.yxyapi.service.tifenbao.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.china08.yxyapi.entity.mg.huixue.YxyHuixuePlan;
import com.china08.yxyapi.repository.mg.huixue.YxyHuixuePlanRepository;
import com.china08.yxyapi.service.tifenbao.TifenbaoPlanStopService;

@Service
public class TifenbaoPlanStopServiceImpl implements TifenbaoPlanStopService {
    @Autowired
    private YxyHuixuePlanRepository yxyHuixuePlanRepository;

    @Override
    @Transactional
    public Integer stopPlan(String id) {
        YxyHuixuePlan yxyHuixuePlan = yxyHuixuePlanRepository.findOne(id);
        yxyHuixuePlan.setStatus(0);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String endDate = sdf.format(new Date());
        yxyHuixuePlan.setEndDate(Integer.parseInt(endDate));
        yxyHuixuePlanRepository.save(yxyHuixuePlan);
        YxyHuixuePlan yxyHuixuePlanupdate = yxyHuixuePlanRepository.findOne(id);
        if (yxyHuixuePlanupdate != null && yxyHuixuePlanupdate.getStatus() == 0) {
            return 1;
        } else {
            return 0;
        }
    }
}
